package org.deadline.service.user;

import java.util.List;
import org.deadline.model.user.UserGroup;
import org.deadline.repository.user.UserGroupRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Service
@Transactional
public class UserGroupServiceImpl implements UserGroupService {

	@Autowired
    UserGroupRepository userGroupRepository;

	public long countAllUserGroups() {
        return userGroupRepository.count();
    }

	public void deleteUserGroup(UserGroup userGroup) {
        userGroupRepository.delete(userGroup);
    }

	public UserGroup findUserGroup(Long id) {
        return userGroupRepository.findOne(id);
    }

	public List<UserGroup> findAllUserGroups() {
        return userGroupRepository.findAll();
    }

	public List<UserGroup> findUserGroupEntries(int firstResult, int maxResults) {
        return userGroupRepository.findAll(new org.springframework.data.domain.PageRequest(firstResult / maxResults, maxResults)).getContent();
    }

	public void saveUserGroup(UserGroup userGroup) {
        userGroupRepository.save(userGroup);
    }

	public UserGroup updateUserGroup(UserGroup userGroup) {
        return userGroupRepository.save(userGroup);
    }
}
